package com.ruoyi.web.controller.module.customer;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.customer.domain.CustomerFinance;
import com.ruoyi.customer.service.ICustomerFinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户财务信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/customer/finance")
public class CustomerFinanceController extends BaseController
{
    @Autowired
    private ICustomerFinanceService customerFinanceService;

    /**
     * 获取客户财务列表
     */
    @PostMapping("/customerFinanceList")
    public TableDataInfo list(@RequestBody CustomerFinance customerFinance, HttpServletRequest request)
    {
        String shopId = request.getHeader("ShopId"); // 店铺id
        if(shopId != null && !shopId.equals("")){
            customerFinance.setShopId(shopId);
        }
        startPageByPost();
        List<CustomerFinance> list = customerFinanceService.selectCustomerFinanceList(customerFinance);
        return getDataTable(list);
    }

    @Log(title = "客户财务管理 - 导出", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('customer:finance:export')")
    @PostMapping("/customerFinanceExport")
    public void export(HttpServletResponse response, CustomerFinance user)
    {
        List<CustomerFinance> list = customerFinanceService.selectCustomerFinanceList(user);
        ExcelUtil<CustomerFinance> util = new ExcelUtil<CustomerFinance>(CustomerFinance.class);
        util.exportExcel(response, list, "客户财务数据");
    }
}
